﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace qf_cms.templates
{
	public partial class subColumn : System.Web.UI.Page
	{
		LogicLayer mgr = new LogicLayer();
		protected string pid = "", cid="", curTitle = "", curContent = "";

		protected void Page_Load(object sender, EventArgs e)
		{
			pid = Request.QueryString["pid"] + "";
			cid = Request.QueryString["cid"] + "";

			if (!string.IsNullOrEmpty(pid) && string.IsNullOrEmpty(cid))
			{
				List<CMS_Columns> colList = mgr.ListColumns(pid);
				if (colList != null && colList.Count > 0)
					cid = colList[0].ColumnID;
			}

			CMS_Columns col = mgr.GetCMS_Columns(cid);
			if (col != null)
			{
				curTitle = col.ColumnName;
			}
		}

		protected void WriteLeftNav()
		{
			List<CMS_Columns> colList = mgr.ListColumns(pid);
			if (colList != null)
			{
				string url = string.Empty;
				foreach (CMS_Columns col in colList)
				{
					url = "/templates/subColumn.aspx?pid=" + pid + "&cid=" + col.ColumnID;
					if (col.ColumnID == cid )
						Response.Write("<a href=\"" + url + "\" class=\"l1on\">" + col.ColumnName + "</a>");
					else
						Response.Write("<a href=\"" + url + "\" >" + col.ColumnName + "</a>");
				}
			}
		}

		protected void WriteContent()
		{
			int n = mgr.GetArticleSum(cid);
			if (n == 1)
			{
				//只有一篇文章
				List<CMS_Article> artList = mgr.ListArticles(cid);
				if (artList != null && artList.Count > 0)
				{
					Response.Write(artList[0].ArticleContent);
				}
			}
			else if (n > 1)
			{
				//如果有多篇文章
				WriteContentList();
			}
		}

		protected void WriteContentList()
		{
			List<CMS_Article> artList = mgr.ListArticles(cid);
			if (artList != null)
			{
				Response.Write("<table>");
				string title = string.Empty;
				foreach (CMS_Article art in artList)
				{
					Response.Write("<tr><td>");

					title = art.ArticleTitle;
					if (title.Length > 30)
						title = title.Substring(0, 30) + "...";

					Response.Write("<a href=\"viewArticle.aspx?aid=" + art.ArticleID + "\" target=\"_blank\" >" + title + "</a>");
					Response.Write("</td></tr>");
				}
				Response.Write("</table>");
			}
		}
	}
}